/*
 * TransactionsLogMBean.java    ver   23/nov/2009
 *
 * Copyright (c) 2009 mentalsmash.org
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * The use of the Apache License does not indicate that this project is
 * affiliated with the Apache Software Foundation.
 */
package org.mentalsmash.tazio.transactions.log;

import org.mentalsmash.tazio.transactions.TransactionStatus;

/**
 * Standard MBean interface for inspecting the transaction's log
 * 
 * @version 0.0.1 23/nov/2009
 * @author Andrea Reale <andrea.reale@gmail.com>
 * 
 */
public interface TransactionsLogMonitorMBean {

    /**
     * Returns the number of active transactions in the log.
     * <p>
     * A transaction is said to be active if it is in one of the following
     * statuses: {@link TransactionStatus#RUNNING},
     * {@link TransactionStatus#LOCAL_VALIDATION},
     * {@link TransactionStatus#GLOBAL_VALIDATION},
     * {@link TransactionStatus#BEGINNING},
     * </p>
     * 
     * @return
     */
    int getNumActiveTransactions();

    /**
     * Returns the number of committed transactions in the log.
     * 
     * @return the number of committed transactions in the log.
     */
    int getNumCommittedTransactions();

    /**
     * Returns the number of rolled back transactions in the log.
     * 
     * @return Returns the number of rolled back transactions in the log.
     */
    int getNumRolledbackTransactions();

    /**
     * Returns the average number of successful commit operations per minute.
     * 
     * @return the average number of successful commit operations per minute.
     */
    double getCommitsPerMinute();

    /**
     * Returns the average number of rollbacks per minute.
     * 
     * @return the average number of rollbacks per minute.
     */
    double getRollbacksPerMinute();

    /**
     * Returns the parameter "Transaction Validity Time", that is the time (in
     * minutes) during which a transaction is considered valid by the log. Once
     * this time has elapsed the transaction is marked cleanable and will be
     * eventually get cleaned by a cleaner thread
     * 
     * @return the "Transaction Validity Time"
     */
    int getTxValidityTime();

    /**
     * Sets the value of "Transaction Validity Time"
     * 
     * @param minutes
     *            the number of minituse for a transaction to be considered
     * 
     * @see #getTxValidityTime() valid by the log
     */
    void setTxValidityTime(int minutes);

    /**
     * Gets the average duration of a transaction.
     * <p>
     * The duration of a transaction is intended to be the number of millisecs
     * elapsing from the moment a transaction enters in the
     * {@link TransactionStatus#BEGINNING} status, to the moment a transaction
     * enters either the {@link TransactionStatus#ROLLED_BACK} or
     * {@link TransactionStatus#COMMITTED} status.
     * </p>
     * 
     * @return the average duration of a transaction in milliseconds as seen by
     *         the log.
     */
    double getAverageTxDuration();
}
